<template>
  <el-form
    ref="formRef"
    v-loading="formLoading"
    :model="formData"
    :rules="formRules"
    label-width="70px"
  >
    <el-row>
      <el-col :xl="12" :lg="12" :md="12" :sm="12" :xs="24">
        <el-form-item label="内部码" prop="id" class="ml-10px mr-10px">
          <el-input style="display:none" />
          <el-input v-model="formData.id" clearable placeholder="请输入" @keyup.enter="focusInput"/>
        </el-form-item>
      </el-col>
    </el-row>
    <!-- <el-divider /> -->
    <el-row>
      <el-col :xl="12" :lg="12" :md="12" :sm="12" :xs="24">
        <el-form-item label="测试结果" prop="rigidity" class="ml-10px mr-10px">
          <el-input v-model="formData.rigidity" clearable placeholder="测试结果" ref="nextFocus" :autosize="{ minRows: 5, maxRows: 40 }"
          type="textarea"/>
        </el-form-item>
      </el-col>
    </el-row>
  </el-form>
  <el-row>
    <el-col :xs="24" class="mt-5px col-big-btn">
      <el-button :disabled="formLoading" type="primary" @click="submitForm" class="big-btn mr-12px">确 定</el-button>
    </el-col>
  </el-row>
</template>

<style lang="scss" scoped>
  .circle-lamp{
    width: 20px;
    height: 20px;
    display: inline-block;
    border: 1px solid #1b841c;
    border-radius: 50%;
    background: #1b841c;
    box-shadow: 1px 1px 27px #1b841c;
    margin: auto 10px;
  }
  @media (max-width: 768px) {
    .col-big-btn{
      text-align: center;
      .big-btn{
        width: 80%;
      }
    }
  }
  
</style>
  
<script lang="ts" setup>
  import * as rigidTestApi from '@/api/hcxly/rigidTest/Index'

  defineOptions({ name: 'rigidTest' })

  const message = useMessage() // 消息弹窗
  const formLoading = ref(false) // 表单的加载中：1）修改时的数据加载；2）提交的按钮禁用
  const formRef = ref() // 表单 Ref
  const emit = defineEmits(['success']) // 定义 success 事件，用于操作成功后的回调
  const rigidTestMsg = ref()
  const formData = reactive({
    id: '',
    rigidity : ''
  })
  const formRules = reactive({
    id: [{ required: true, message: '内码不能为空', trigger: 'blur' }]
  })
  
  /** 提交表单 */
  const submitForm = async () => {
    console.log(formData)
    // 校验表单
    if (!formRef) return
    const valid = await formRef.value.validate()
    if (!valid) return
    // 提交请求
    formLoading.value = true
    try {
    rigidTestMsg.value = await rigidTestApi.updateRigidTest(formData)
      // console.log(weightmsg)
      message.success('修改成功')
    } finally {
      formLoading.value = false
      // 清空，从而触发刷新data
      resetForm()
    }
  }

  /** 重置表单 */
  const resetForm = () => {
    formData.id = ''
    formData.rigidity = ''
    formRef.value?.resetFields()
  }

  // 创建一个引用，用于密码输入框元素
  const nextFocus = ref(null);
  /** 回车聚焦到下一个输入框 */
  const focusInput = () => {
    nextFocus.value.focus();
  }
</script>
  